Skip to main content

SDK for Tailslide


Installation


Install the Tailslide npm package with

  • Node.js: npm install tailslide
  • Go: go get github.com/tailslide-io/tailslide.go
  • Python: pip install tailslide-sdk
  • Node.js: gem install tailslide

Basic Usage


Instantiating and Initializing FlagManager

The FlagManagerclass is the entry point of this SDK. It is responsible for retrieving all the flag rulesets for a given app with its appId and creating new Toggler instances to handle toggling of feature flags within that app. To instantiate a FlagManager object, a user must provide a configuration object:

const FlagManager = require('tailslide');

const config = {
natsServer: 'nats://localhost:4222',
natsStream: 'flags_ruleset',
appId: 1,
userContext: '375d39e6-9c3f-4f58-80bd-e5960b710295',
sdkKey: 'myToken',
redisHost: 'http://localhost',
redisPort: 6379,
};

const manager = new FlagManager(config);
await manager.initialize();
  • natsServer is the NATS JetStream server address:port
  • natsStream is the NATS JetStream’s stream name that stores all the apps and their flag rulesets
  • appId is the ID number of the app the user wants to retrieve its flag ruleset from
  • userContext is the UUID string that identifies the current user
  • sdkKey is the SDK key for the Tailslide, it is used as a password for NATS JetStream token authentication
  • redisHost is the address to the Redis database
  • redisPort is the port number that the Redis database runs on

After instantiating a FlagManager, invoke the initialize method. This method connects the FlagManager instance to both NATS JetStream and Redis Timeseries, and asynchronously retrieves the latest and any new flag ruleset data.


Using Feature Flag with Toggler

Once the FlagManager is initialized, it can create a Toggler, with the newToggler method, for each feature flag that the developer wants to wrap the new and old features in. A Toggler’s isFlagActive method checks whether the flag with its flagName is active or not based on the flag ruleset. A Toggler’s isFlagActive method returns a boolean value, which can be used to evaluate whether a new feature should be used or not.

const flagConfig = {
flagName: 'App 1 Flag 1',
};

const flagToggler = manager.newToggler(flagConfig);

if (flagToggler.isFlagActive()) {
// call new feature here
} else {
// call old feature here
}

Emitting Success or Failture

To use a Toggler instance to record successful or failed operations, call its emitSuccess or emitFailure methods:

if (successCondition) {
await flagToggler.emitSuccess();
} else {
await flagToggler.emitFailure();
}

Documentation


For language specific documentation, please see README files at the following links:

JavaScript: https://github.com/tailslide-io/tailslide.js

Ruby: https://github.com/tailslide-io/tailslide.rb

Python: https://github.com/tailslide-io/tailslide.py

Golang: https://github.com/tailslide-io/tailslide.go